package com.zh.system.domain.entity;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.zh.web.base.BaseModel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.ibatis.type.ArrayTypeHandler;

import java.io.Serializable;

@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@TableName("sys_msg_template")
@ApiModel("消息模板表")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class SysMsgTemplate extends BaseModel implements Serializable {
    private static final long serialVersionUID = 1L;
    @TableId
    @ApiModelProperty("模板主键")
    private Long id;
    @ApiModelProperty("模板名称")
    private String name;
    @ApiModelProperty("模板类型")
    private String type;
    @ApiModelProperty("模板来源")
    private String source;
    @ApiModelProperty("模板体")
    private String template;
    @ApiModelProperty("模板替换关键词（体）数组")
    private String keyword;
    @TableField(exist = false)
    private String[] keywords;

    public void toKeyword() {
        if (keywords != null && keywords.length != 0) {
            this.keyword = String.join(",", keywords);
        }
    }

    public void toKeywords() {
        if (StrUtil.isNotEmpty(keyword)) {
            this.keywords = keyword.split(",");
        }
    }
}